<template>
  <div class="header">
    <!-- Logo区域 -->
    <div class="logo-container">
      <div class="logo" @click="goToHome">
        <img src="/Logo.png" alt="Atopos Logo" class="logo-image" />
        <span class="logo-text"><span style="color: #FF7500;">A</span><span style="color: #888888;">topos</span></span>
      </div>
    </div>

    <!-- 面包屑导航 -->
    <div class="breadcrumb-container">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item v-for="(item, index) in breadcrumbs" :key="index">
          {{ item }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="user-info">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          管理员
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="profile">个人中心</el-dropdown-item>
            <el-dropdown-item command="settings">设置</el-dropdown-item>
            <el-dropdown-item divided command="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';
import { ArrowDown } from '@element-plus/icons-vue';

const router = useRouter();
const route = useRoute();

// 点击Logo跳转到首页
const goToHome = () => {
  router.push('/');
};

// 根据当前路由生成面包屑
const breadcrumbs = computed(() => {
  const path = route.path;
  const breadcrumbMap = {
    '/': ['数据概览'],
    '/student-manage': ['学生管理', '学生列表'],
    '/student-add': ['学生管理', '添加学生'],
    '/teacher-manage': ['教师管理', '教师列表'],
    '/teacher-add': ['教师管理', '添加教师'],
    '/course-manage': ['课程管理', '课程列表'],
    '/course-add': ['课程管理', '添加课程'],
    '/class-manage': ['班级管理', '班级列表'],
    '/class-add': ['班级管理', '添加班级'],
    '/grade-manage': ['成绩管理', '成绩列表'],
    '/grade-add': ['成绩管理', '录入成绩'],
    '/role-manage': ['角色管理'],
    '/dictType-manage': ['字典管理']
  };

  return breadcrumbMap[path] || ['未知页面'];
});

// 处理下拉菜单命令
const handleCommand = (command) => {
  switch (command) {
    case 'profile':
      router.push('/profile');
      break;
    case 'settings':
      router.push('/settings');
      break;
    case 'logout':
      ElMessage.success('已退出登录');
      router.push('/login');
      break;
  }
};
</script>

<style scoped>
/* 顶部导航栏样式 */
.header {
  height: 60px;
  background-color: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 10;
}

/* Logo样式 */
.logo-container {
  margin-right: 30px;
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.logo:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.logo-image {
  height: 32px;
  width: auto;
  object-fit: contain;
  max-width: 120px;
}

.logo-text {
  font-size: 20px;
  font-weight: bold;
  margin-left: 8px;
  font-family: 'Arial', sans-serif;
  white-space: nowrap;
}

/* 面包屑样式 */
.breadcrumb-container {
  font-size: 14px;
  flex: 1;
}

.user-info {
  cursor: pointer;
}

.el-dropdown-link {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #606266;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header {
    padding: 0 10px;
  }

  .logo-container {
    margin-right: 15px;
  }

  .logo-text {
    font-size: 16px;
  }

  .breadcrumb-container {
    display: none;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 0 5px;
  }

  .logo-container {
    margin-right: 10px;
  }

  .logo-text {
    display: none;
  }
}
</style>